<template>
	<view>
		<view class="content">
			<view class="con_row">
				<input class="text_input" type="text"  placeholder="请输入真实姓名" v-model="realName"/>
			</view>
			<view class="con_row">
				<input class="text_input" type="idcard"  placeholder="请输入身份证号码" v-model="cardNumber">
			</view>
			<view class="up">
				<view class="top">上传身份证照片</view>
				<view class="upall">
					<view class="zheng">
						<view class="one" >
							<image class="upImg" @tap="chooseImage" :src="cardFront" v-if="cardFront !=''" mode="aspectFit"></image>
							<image class="upImg" @tap="chooseImage" src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/backzheng.png" v-if="cardFront==''"></image>
						</view>
						<view class="tit">上传身份证正面</view>
					</view>
					<view class="zheng">
						<view class="one">
							<image class="upImg" @tap="chooseImageTwo" :src="cardReverse" v-if="cardReverse !=''" mode="aspectFit"></image>
							<image class="upImg" @tap="chooseImageTwo" src="https://taobaoke-paimai.oss-cn-beijing.aliyuncs.com/backfan.png" v-if="cardReverse==''"></image>
						</view>
						<view class="tit">上传身份证反面</view>
					</view>
				</view>	
			</view>
				
			<view class="con_btn" @tap="setRecharge">提交</view>	
				
		</view>
			
			
		
		
	</view>
	
</template>

<script>
	import urlConfig from '@/common/api/config.js'
	export  default{
		data(){
			return{
				realName:''   ,// 真实姓名
				cardNumber:'',  // 身份证号
				cardFront:'' , // 身份证正面
				cardReverse:'' ,// 身份证反面
				id:''   // 重新申请id
				
				
			}
		},
		onLoad(options) {
			console.log(options)
			if (Object.keys(options).length != 0) {
				this.id = options.id
			}
		},
		methods:{
			//  身份证正面
			chooseImage () {
				let that = this;
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album','camera'], //从相册选择
				    success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: urlConfig + 'uploadService', //接口地址
							filePath: tempFilePaths[0],
							name: 'file',
							success: (res) => {
								console.log(res); 
								var data = JSON.parse(res.data);
								// that.cardFront = data.data.replace(/\"/g, "");
								that.cardFront = data.data.data
							}
						});
					}
				});	
			},
			// 身份证反面
			chooseImageTwo () {
				let that = this;
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album','camera'], //从相册选择
				    success: (chooseImageRes) => {
				            const tempFilePaths = chooseImageRes.tempFilePaths;
				            uni.uploadFile({
				                url: urlConfig + 'uploadService', //接口地址
				                filePath: tempFilePaths[0],
				                name: 'file',
				                success: (res) => {
									console.log(res); 
									var data = JSON.parse(res.data);
									console.log(data,"======")
									that.cardReverse = data.data.data
									
				                }
				            });
				        }
				});	
			},
			setRecharge: function () {
				let that = this;
				if (that.realName == '') {
					uni.showToast({
						icon:'none',
						title:'请输入真实姓名'
					})
					return false;
				} else if (that.cardNumber == '') {
					uni.showToast({
						icon:'none',
						title:'请输入身份证号码'
					})
					return false;;
				} else if (that.cardFront == '') {
					uni.showToast({
						icon:'none',
						title:'请上传身份证正面'
					})
					return false;
				} else if (that.cardReverse == '') {
					uni.showToast({
						icon:'none',
						title:'请上传身份证反面'
					})
					return false;
				} 
				that.api.authentication({
					realName:that.realName,
					cardNumber:that.cardNumber,
					cardFront:that.cardFront,
					cardReverse:that.cardReverse,
					id:that.id
				}).then(res => {
					console.log(res)
					that.tui.toast(res.data)
					uni.$emit('login',{msg:'更新信息'});
					that.cacheHelper.updateUserInfo()
					setTimeout(function () {
						uni.navigateBack({
							delta: 1
						});
					},500)
				})
				
			}
			
			
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 20upx;
		letter-spacing: 3upx;
		border-top: 20rpx solid #F5F5F5;
	}
	.content {
		width: 100%;
		box-sizing: border-box;
		.con_row {
			width: 100%;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			padding: 20upx;
			font-size: 32upx;
			color: #666666;
			background: #FFFFFF;
			margin-bottom: 20upx;
			border-radius: 16upx;
			line-height: 50upx;
			border-bottom: 2rpx solid #F4F4F4;
			.row_l {
				width: 200upx;
				box-sizing: border-box;
			}
			.row_txt {
				width: calc(100% - 200upx);
				box-sizing: border-box;
			}
			.text_input {
				width: 100%;
				box-sizing: border-box;
				height: 50upx;
				line-height: 50upx;
			}
			
		}
		.con_btn {
			width: 94%;
			box-sizing: border-box;
			margin: 327rpx auto 0 auto;
			text-align: center;
			line-height: 94rpx;
			background: #E42221;
			color: #FFFFFF;
			border-radius: 8rpx;
		}
	}
	.up{
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 20upx 40upx;
		border-radius: 16upx;
		.top{
			font-size: 32upx;
			padding: 20rpx 0 50rpx 0;
		}
		.upall{
			width: 100%;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 20upx 0;
			.zheng{
				width: 276upx;
				box-sizing: border-box;
				.one{
					width: 276upx;
					height: 188upx;
					box-sizing: border-box;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.tit{
					color: #666666;
					font-size: 22upx;
					text-align: center;
					padding-top: 22upx;
				}
			}
		
		}
		
	}
	

	
	
	
	
	
</style>
